<?php
try{
	$pdo = new PDO('mysql:host=localhost; dbname=exercise', 'root', 'root');
	$sql = 'select id,username,email from user';
	$stmt = $pdo->query($sql);
	//var_dump($stmt);
	//echo "<hr/>";	
	
	//foreach条件遍历数组
	foreach($stmt as $row) {
		echo "编号：".$row['id']."<br/>";
		echo "用户名：".$row['username']."<br/>";
		echo "邮箱：".$row['email']."<br/>";
	}
}catch(PDOException $e) {
	echo $e->getMessage();
}
?>